package com.sfx.controller;

import com.sfx.component.UserComponent;
import com.sfx.model.User;
import com.sfx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

//和前端进行交互的第一层(主要验证前端传递过来的参数-->进行校验和验证==>相当于安检的作用)
@Controller
public class UserController {
    //我们这里假设要在UserController类里面使用UserService,前提是UserService已经存放到Spring中了(加了类注解了)
    private UserService userService;//UserService成员属性

    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void sayHello(){
        userService.doUserService1();
        System.out.println("do UserController!!!");
    }

//    //setter注入
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }


//    //构造方法注入
//    private UserService userService;//UserService成员属性
//
//    @Autowired  //可以省略
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }
//    //构造方法注入两个对象
//    private final UserService userService;//userService成员属性
//    private UserComponent userComponent;//userComponent成员属性
//
//    @Autowired()  //可以省略
//    public UserController(UserService userService,UserComponent userComponent) {
//        this.userService = userService;
//    }


    //在 Spring 项⽬中,通过 main ⽅法获取到Controller类,⽤Controller⾥⾯通过注⼊的⽅式调⽤Service类,
    //Service 再通过注⼊的⽅式获取到 Repository类，Repository类⾥⾯有⼀个⽅法构建⼀个 User 对象,
    //返回给 main ⽅法。Repository ⽆需连接数据库，使⽤伪代码即可
}
